// home/pages/TrialCalculation/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    country:'',
    country_code:'',
    is_sensitive:0,
    show:false,
    list:[],
    active:0,
    weight:1,
    length:'',
    width:'',
    height:'',
    the_show:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },
  show_country(){
    this.selectComponent('#country').show_demo()
  },
  get_country(e){
    this.setData({
      country_code:e.detail.value,
      country:e.detail.title
    })
  },
  show_popup(){
    this.setData({
      show:true
    })
  },
  onClose(){
    this.setData({
      show:false
    })
  },
  get_index(e){
    let index=e.currentTarget.dataset.index
    this.setData({
      is_sensitive:index,
      show:false
    })
  },
  onChange(e){
    this.setData({
      weight:e.detail
    })
  },
  get_length(e){
    this.setData({
      length:e.detail.value
    })
  },
  get_width(e){
    this.setData({
      width:e.detail.value
    })
  },
  get_height(e){
    this.setData({
      height:e.detail.value
    })
  },
  confirm(){
    const that=this;
    if(!that.data.country_code){
      app.toast('请选择国家')
      return false
    }
    app.wxRequest('/api/Pack/calculateShippingCost',{
      country:that.data.country_code,
      weight:that.data.weight,
      length:that.data.length,
      width:that.data.width,
      height:that.data.height,
      goods_type_id:that.data.is_sensitive==1?1:''
    },function(res){
      if(res.code==200){
        that.setData({
          the_show:true,
          list:res.data
        })
      }else{
        app.toast(res.message)
      }
    })
  },
  change_tab(e){
    this.confirm()
    console.log(e)
  },
  route_details(e){
    let item=e.currentTarget.dataset.item;
    wx.setStorageSync('item', JSON.stringify(item))
    wx.navigateTo({
      url: '/home/pages/route_details/index',
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})